package com.controller;

import com.domain.User;
import com.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/get/{id}")
    public User findById(@PathVariable("id") int user_id) {
        User user = userService.findById(user_id);
        return user;
    }

    @GetMapping("/get/user/list")
    public List<User> getUserList() {
        return userService.getUserList();
    }

    @GetMapping("/update/{id}/{pwd}")
    public User updateUser(@PathVariable("id") int user_id,
                           @PathVariable("pwd") String pwd) {
        User user = userService.findById(user_id);
        user.setPwd(pwd);
        User updateUserd = userService.updateUser(user);
        return updateUserd;
    }

    @GetMapping("/delete/{id}")
    public void deleteUser(@PathVariable("id") int user_id) {
        userService.deleteUser(user_id);
    }
}
